﻿using SQLiteDB;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using Utils.Common;
using ZK.Entity;

namespace ZK.BLL
{
  public  class CIJTemplateBLL
    {
        private CIJTemplateBLL() { }
        /// <summary>
        /// 窗体对象实例
        /// </summary>
        private static CIJTemplateBLL _instance;
        public static CIJTemplateBLL Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new CIJTemplateBLL();
                return _instance;
            }
        }


        public Font GetFont( string fontName)
        {
            string[] ls = fontName.Split(',');

          return  new Font(ls[0], float.Parse(ls[1]), ls[2] == "加粗" ? FontStyle.Bold : FontStyle.Regular);
        }

        public string  Font2String(Font font)
        {
            string bold = font.Bold ? "加粗" : "不加粗";
            return $"{ font.FontFamily.Name},{font.Size},{bold}";
        }

        public string GetNewID()
        {
            return BaseIdGenerator.Instance.GetId();
        }

        public List<CIJTemplate> GetList()
        {
            List<CIJTemplate> list;
            string sql = "Select * from CIJTemplate  Order BY Id ";
            list = SQLiteORM.Instance.GetEntityList<CIJTemplate>(sql);
            return list;
        }

        public bool Insert(CIJTemplate template)
        {
            
            return SQLiteORM.Instance.Insert<CIJTemplate>(template);
        }


        public bool DeleteById(string id)
        {
            return SQLiteORM.Instance.Delete($"DELETE FROM CIJTemplate WHERE Id='{id}'");
        }


        public  CIJTemplate GetByTemplateName(string templateName)
        {
            
            string sql = $"Select * from CIJTemplate WHERE TemplateName ='{templateName}'  ";
            return SQLiteORM.Instance.GetEntity<CIJTemplate>(sql);
            
        }
    }
}
